package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.RubbishBinReportDao;
import cn.topevery.garden.entity.po.RubbishBinReport;
import cn.topevery.garden.entity.query.RubbishBinReportQuery;
import cn.topevery.garden.entity.vo.RubbishBinReportVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 垃圾桶满溢信息表
 *
 * @author code-generate
 * @date 2021-08-18
 */
@Repository
public class RubbishBinReportDaoImpl extends BaseDaoImpl<RubbishBinReport> implements RubbishBinReportDao {
    @Override
    public <P extends DbCsp> List<RubbishBinReport> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<RubbishBinReportVO> listPage(RubbishBinReportQuery query) {
        String table = "t_rubbish_bin_report trbr left join t_device_warning tdw on trbr.c_id = tdw.c_main_id and tdw.c_type = 'd408daf6-1fc9-49a8-9927-ba53ff07a9f3'";

        String columns = "trbr.*,tdw.c_warning_status,tdw.c_event_code";
        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("trbr.c_id desc");
        sqlQueryMate
                .where(true, "trbr.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotBlank(query.getTemId()), "trbr.c_device_code", ScriptConditionEnum.Eq, query.getTemId());

        return getDataPager(sqlQueryMate, pageSize, pageIndex, RubbishBinReportVO.class);
    }

    @Override
    public RubbishBinReport getEntityByColumn(String key, String value) {
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }

    @Override
    public List<Map<String, Object>> rubbishBinInfo() {
        String sql = "select DATE_FORMAT(t.c_db_create_date, '%H:%i') date,IFNULL(t.c_brim_over_height, 0) value,t.c_device_code deviceCode from t_rubbish_bin_report t where t.c_db_create_date >= CURDATE()";
        return getMap(sql);
    }
}
